//
//  SINAScoreQueryViewController.m
//  sinashebao
//
//  Created by  androidlongs on 2018/1/2.
//  Copyright © 2018年  androidlongs. All rights reserved.
//

#import "SINAScoreQueryViewController.h"
#import "SINATecManagerQuerScoreItemTableViewCell.h"
#import "SINATeachManaQueryScoreModel.h"
#import "SINATecScoreQueryDetailListViewController.h"


@interface SINAScoreQueryViewController ()
<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UIView *scoreQueryView;
@property (strong, nonatomic)  UITableView *mainContentTableView;
@property(nonatomic,strong) NSMutableArray *dataList;
// 刷新中得状态判断，只读属性，根据状态可做一些自定义的事情
@property (nonatomic, readonly, getter=isRefreshing) BOOL refreshing;

//搜索框
@property (weak, nonatomic) IBOutlet UIView *searchView;


@end

@implementation SINAScoreQueryViewController
-(NSMutableArray *)dataList{
    if (!_dataList) {
        _dataList = [NSMutableArray array];
    }
    return  _dataList;
}
-(UITableView *)mainContentTableView{
    if (!_mainContentTableView) {
        _mainContentTableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, mainW, mainH)];
    }
    return _mainContentTableView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBarHidden = NO;
    self.navigationItem.title=self.pageType;
    self.mainContentTableView.delegate=self;
    self.mainContentTableView.dataSource=self;
    self.mainContentTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    self.mainContentTableView.backgroundColor=[UIColor colorWithHexString:@"#fafafa"];
    self.mainContentTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.scoreQueryView addSubview:self.mainContentTableView];
    [self initTestData];
    [self.mainContentTableView reloadData];
    [self commonFunction];
    
    
}

-(void)commonFunction{
    if ([self.pageType isEqualToString:@"点名查询"]) {
        [self loadingSubClassNetData];
        //隐藏搜索
        self.searchView.hidden=YES;
        self.scoreQueryView.frame=CGRectMake(0, 0, mainW, mainH-48-22);
        self.mainContentTableView.frame=CGRectMake(0, 0, mainW, CGRectGetHeight(self.scoreQueryView.frame));
    } else {
        //成绩查询
        //显示搜索
        self.searchView.hidden=NO;
        self.scoreQueryView.frame=CGRectMake(0, 48, mainW, mainH-110);
        self.mainContentTableView.frame=CGRectMake(0, 0, mainW, CGRectGetHeight(self.scoreQueryView.frame));
        [self loadingSubClassNetData];
        
        //2018-6-11 日 1.0版本 修改需求 去掉搜索功能
        //隐藏搜索
        self.searchView.hidden=YES;
        self.scoreQueryView.frame=CGRectMake(0, 0, mainW, mainH-48-22);
        self.mainContentTableView.frame=CGRectMake(0, 0, mainW, CGRectGetHeight(self.scoreQueryView.frame));
    }
}
-(void)initTestData{
    for (NSInteger i=0; i<0; i++) {
        SINATeachManaQueryScoreModel *model = [[SINATeachManaQueryScoreModel alloc]init];;
        [self.dataList addObject:model];
    }
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataList.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    SINATecManagerQuerScoreItemTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SINATecManagerQuerScoreItemTableViewCell"];
    
    if (cell == nil) {
        cell= [[[NSBundle mainBundle]loadNibNamed:@"SINATecManagerQuerScoreItemTableViewCell" owner:nil options:nil] firstObject];
        
    }
    
    cell.itemClickBlock = ^(SINASubClassModel *model) {
        DLog(@"详情");
        
        SINATecScoreQueryDetailListViewController *controller = [[SINATecScoreQueryDetailListViewController alloc]initWithNibName:@"SINATecScoreQueryDetailListViewController" bundle:nil];
        controller.model = model;
        controller.pageType=self.pageType;
        [self.navigationController pushViewController:controller animated:YES];
        
    };
    
    cell.pageFlag=1;
    cell.model=self.dataList[indexPath.row];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell ;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 117;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath{
//    NSInteger index = indexPath.row;
    
    
}
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */



//成绩查询 getClassifyByTeacherUuidUrl
-(void)loadingSubClassNetData{

    [self startLoading];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
    
    [dict setObject:[[SINACommonUserHelper share]getUserModel].userUid forKey:@"uuid"];
    
    WeakSelf;
    [CXAFNHttpRequestUtils httpGetRequest:[NSString stringWithFormat:@"%@%@",baseUrl,getClassifyByTeacherUuidUrl] withParamters:dict success:^(id responseData) {
        
        NSString *code = responseData[@"code"];
        [weakSelf stopLoading];
        if ([code isEqualToString:@"1000"]) {
            NSMutableArray *result = responseData[@"content"];
            if (result!=nil&&result.count>0) {
                for (NSInteger i=0; i<result.count; i++) {
                    NSDictionary *dict=result[i];
                    SINASubClassModel *model = [[SINASubClassModel alloc]initWithDict:dict];
                    [self.dataList addObject:model];
                }
                self.mainContentTableView.hidden=NO;
                [self.mainContentTableView reloadData];
            }else{
                [YPXToastView showToastViewWithText:@"暂无班级数据 " andDuration:3 andParentView:self.mainContentTableView];
            }
            
        }else{
//            NSString *message =responseData[@"message"];
//            WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:message sureBtn:@"确定"
//                                                                 cancleBtn:nil];
            //[alertView showXLAlertView];
            //self.noDataLabel.hidden=NO;
            //self.mainContentTableView.hidden=YES;
            [YPXToastView showToastViewWithText:@"加载班级数据异常 " andDuration:3 andParentView:self.mainContentTableView];
        }
     
    } failure:^(NSError *error, NSInteger errCode) {
        DLog(@"加载 失败  %@ ",error.debugDescription);
        [weakSelf stopLoading];
//        WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:@"加载数据失败" sureBtn:@"确定"
//                                                             cancleBtn:nil];
        //[alertView showXLAlertView];
        //        self.noDataLabel.hidden=NO;
        //        self.mainContentTableView.hidden=YES;
        [YPXToastView showToastViewWithText:@"加载班级数据异常 " andDuration:3 andParentView:self.mainContentTableView];
    }];
}

@end
